<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns the timezone offset</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="datetime.format.html">« DateTimeInterface::format</a></li>
      <li style="float: right;"><a href="datetime.gettimestamp.html">DateTimeInterface::getTimestamp »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.datetimeinterface.html">DateTimeInterface</a></li>
    <li>Returns the timezone offset</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="datetime.getoffset" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DateTimeInterface::getOffset</h1>
  <h1 class="refname">DateTimeImmutable::getOffset</h1>
  <h1 class="refname">DateTime::getOffset</h1>
  <h1 class="refname">date_offset_get</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DateTimeInterface::getOffset</span> -- <span class="refname">DateTimeImmutable::getOffset</span> -- <span class="refname">DateTime::getOffset</span> -- <span class="refname">date_offset_get</span> &mdash; <span class="dc-title">Returns the timezone offset</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-datetime.getoffset-description">
  <h3 class="title">说明</h3>
  <p class="para">面向对象风格</p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DateTimeInterface::getOffset</strong></span>(): <span class="type">int</span></div>

  <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><strong>DateTimeImmutable::getOffset</strong></span>(): <span class="type">int</span></div>

  <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><strong>DateTime::getOffset</strong></span>(): <span class="type">int</span></div>

  <p class="para rdfs-comment">过程化风格</p>
  <div class="methodsynopsis dc-description"><span class="methodname"><a href="function.date-offset-get.html" class="methodname">date_offset_get</a></span>(<span class="methodparam"><span class="type"><a href="class.datetimeinterface.html" class="type DateTimeInterface">DateTimeInterface</a></span> <code class="parameter">$object</code></span>): <span class="type">int</span></div>

  <p class="para rdfs-comment">
   Returns the timezone offset.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-datetime.getoffset-parameters">
  <h3 class="title">参数</h3>
  <dl>
   <dt>
<code class="parameter">object</code></dt>

<dd>
<p class="para">仅为过程化风格：由 <span class="function"><a href="function.date-create.html" class="function">date_create()</a></span> 返回的 <span class="classname"><a href="class.datetime.html" class="classname">DateTime</a></span> 类型的对象。</p></dd>

  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-datetime.getoffset-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the timezone offset in seconds from UTC on success.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-datetime.getoffset-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       Prior to this version, <strong><code>false</code></strong> was returned on failure.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-datetime.getoffset-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2038">
   <p><strong>示例 #1 <span class="function"><strong>DateTime::getOffset()</strong></span> example</strong></p>
   <div class="example-contents"><p>面向对象风格</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$winter&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">(</span><span style="color: #DD0000">'2010-12-21'</span><span style="color: #007700">,&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTimeZone</span><span style="color: #007700">(</span><span style="color: #DD0000">'America/New_York'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$summer&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">(</span><span style="color: #DD0000">'2008-06-21'</span><span style="color: #007700">,&nbsp;new&nbsp;</span><span style="color: #0000BB">DateTimeZone</span><span style="color: #007700">(</span><span style="color: #DD0000">'America/New_York'</span><span style="color: #007700">));<br /><br />echo&nbsp;</span><span style="color: #0000BB">$winter</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getOffset</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">$summer</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getOffset</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>过程化风格</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$winter&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date_create</span><span style="color: #007700">(</span><span style="color: #DD0000">'2010-12-21'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">timezone_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'America/New_York'</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$summer&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">date_create</span><span style="color: #007700">(</span><span style="color: #DD0000">'2008-06-21'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">timezone_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'America/New_York'</span><span style="color: #007700">));<br /><br />echo&nbsp;</span><span style="color: #0000BB">date_offset_get</span><span style="color: #007700">(</span><span style="color: #0000BB">$winter</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">date_offset_get</span><span style="color: #007700">(</span><span style="color: #0000BB">$summer</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
-18000
-14400
</pre></div>
   </div>
   <div class="example-contents"><p>
    Note: -18000 = -5 hours, -14400 = -4 hours.
   </p></div>
  </div>
 </div>


</div></div></div></body></html>